package com.sso.client.util;


import com.google.gson.Gson;
import com.sso.client.model.ResponseCode;

public class RespUtil {

    public static String respErr() {
        return new RespObj(ResponseCode.FAILED,"请求失败").toString();
    }
    public static String respErr(String msg) {
        return new RespObj(ResponseCode.CODE_ERR, msg).toString();
    }

    public static String respTokenErr(String msg) {
        return new RespObj(ResponseCode.CODE_TOKEN_ERR, msg).toString();
    }

    public static String respSucc() {
        return new RespObj(ResponseCode.SUCCESS,"请求成功").toString();
    }

    public static String respSucc(Object data) {
        return new RespObj(ResponseCode.SUCCESS,"请求成功",data).toString();
    }
}

/**
 * 回复请求格式
 */
class RespObj {
    int ret_code;
    String ret_msg;
    Object data;

    public RespObj(int ret_code, String msg) {
        this.ret_code = ret_code;
        this.ret_msg = msg;
    }

    public RespObj(String json) {
        this.data=json;
    }

    public RespObj(int ret_code,String msg,Object data) {
        this(ret_code,msg);
        this.data =data;
    }

    public int getRet_code() {
        return ret_code;
    }

    public void setRet_code(int ret_code) {
        this.ret_code = ret_code;
    }

    public String getRet_msg() {
        return ret_msg;
    }

    public void setRet_msg(String ret_msg) {
        this.ret_msg = ret_msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        Gson gson=new Gson();

        String s= gson.toJson(this);
        return s;
    }
}